package com.partners.controller.test;

/**
 * @author liangyongle
 * @date 2019-02-12
 */
public class Threads implements Runnable{

    //volatile 保证了线程可以正确读取其它线程写入的值
    volatile  boolean KeepRunning = true;

    @Override
    public void run() {
        while(KeepRunning){
            //发动五连击
            for (int i=0;i<2;i++){
                System.out.println(Thread.currentThread().getName()+"进攻【"+i+"】");
                //让出了处理器时间
                Thread.yield();
            }
        }
        System.out.println(Thread.currentThread().getName()+"结束战斗");
    }
}
